<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<script>
    // 1.普通的递归
    function factorial(num) {
        console.log('我进来了')
        if (num <= 1) {
            return 1;
        } else {
            // return num * factorial(num - 1);
            return num * arguments.callee(num - 1);
        }
    }

    // 2.如果更改指向
    let anotherFactorial = factorial;
    factorial = null;
    // console.log(anotherFactorial(4)) // 我进来了   然后到else那里报错
    console.log(anotherFactorial(4)) // 我进来了*4   24

    // 3.严格模式下arguments.callee会报错,可以使用如下替代
    const factorial2 = function f(num) {
        if (num <= 1) {
            return 1;
        } else {
            return num * f(num - 1);
        }
    };

    console.log(factorial2(4))  // 24
</script>
</body>
</html>